package com.okcl.manager.controller;

import com.okcl.manager.service.CommonService;
import com.okcl.model.vo.common.Result;
import com.okcl.model.vo.common.ResultCodeEnum;
import com.okcl.model.vo.system.ValidateCodeVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

@RestController
@Slf4j
@Tag(name = "通用接口")
@RequestMapping("/common")
public class CommonController {
    @Resource
    private CommonService commonService;

    @Operation(summary = "获取验证码接口")
    @GetMapping("/generateValidateCode")
    public Result getValidateCode() {
        ValidateCodeVo validateCodeVo = commonService.genderateValidateCode();
        return Result.build(validateCodeVo, ResultCodeEnum.SUCCESS);
    }

    /**
     * 上传文件接口
     *
     * @return
     */
    @Operation(summary = "上传文件接口")
    @PostMapping("/uploadFile")
    public Result uploadFile(@RequestParam(value = "file") MultipartFile file) {
        String url = commonService.upload(file);
        return Result.build(url, ResultCodeEnum.SUCCESS);
    }
}
